Skip to content

Conversation

elmiko
Copy link
Contributor

@elmiko elmiko commented Sep 29, 2025

What type of PR is this?

/kind cleanup
/kind api-change

What this PR does / why we need it:

This patch series changes an argument to the NewCloudProvider function to use an AutoscalerOptions struct instead of AutoscalingOptions. This change allows cloud providers to have more control over the core functionality of the cluster autoscaler.

In specific, this patch series also adds a method named RegisterScaleDownNodeProcessor to the AutoscalerOptions so that cloud providers can inject a custom scale down processor.

Lastly, this change adds a custom scale down processor to the clusterapi provider to help it avoid removing the wrong instance during scale down operations that occur during a cluster upgrade.

Which issue(s) this PR fixes:

Fixes #8494

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area area/cluster-autoscaler area/provider/alicloud Issues or PRs related to the AliCloud cloud provider implementation area/provider/aws Issues or PRs related to aws provider and removed do-not-merge/needs-area labels Sep 29, 2025
@k8s-ci-robot k8s-ci-robot added the area/provider/azure Issues or PRs related to azure provider label Sep 29, 2025
@k8s-ci-robot k8s-ci-robot added area/provider/cluster-api Issues or PRs related to Cluster API provider area/provider/coreweave area/provider/digitalocean Issues or PRs related to digitalocean provider area/provider/equinixmetal Issues or PRs related to the Equinix Metal cloud provider for Cluster Autoscaler size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/provider/externalgrpc Issues or PRs related to the External gRPC provider area/provider/gce area/provider/hetzner Issues or PRs related to Hetzner provider area/provider/huaweicloud area/provider/ionoscloud area/provider/kwok Issues or PRs related to the kwok cloud provider for Cluster Autoscaler area/provider/linode Issues or PRs related to linode provider area/provider/magnum Issues or PRs related to the Magnum cloud provider for Cluster Autoscaler area/provider/oci Issues or PRs related to oci provider area/provider/rancher area/provider/utho Issues or PRs related to Utho provider labels Sep 29, 2025
@elmiko
Copy link
Contributor Author

elmiko commented Sep 29, 2025

this is an alternate solution instead of #8531

}

// Check if any of the old MachineSets still have replicas
replicas, found, err := unstructured.NestedInt64(ms.UnstructuredContent(), "spec", "replicas")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think checking spec first, then status, is the least expensive order, but wanna think out loud and double-check.

When a "new" MachineSet is replacing an "old" MachineSet in the service of a change to the corresponding MachineDeployment, it will first reduce the spec count, and then rely upon the infra provider to validate deletion, and then the MachineSet will apply the final reduction to its status.

If the above is ~true, then I think this is the right way to process through a MachineSet resource representation to definitively determine whether or not the "parent" MachineDeployment resource is in any active state of rolling out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am less familiar with the upgrade logic inside of cluster-api, i would again defer to @sbueringer here for an answer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the above is ~true

It is

}

if len(machineSets) == 0 {
// No MachineSets => MD is not rolling out.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the specific scenarios that would produce a MachineDeployment with zero corresponding MachineSet resources?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question, this code is taken from a patch that @sbueringer developed. i'll let him answer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MachineDeployment was created but MD controller did not create MS yet.
Should usually just occur for a very short period of time, but I would prefer handling it explicitly vs going through the code below without any MS

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, makes sense. Do we really want to tag a MachineDeployment in such a state as a candidate for scale down? I would think we would return true, nil here.

Copy link
Member

@sbueringer sbueringer Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, in general there will be at most Machines of the new MS if there are even Machines. And it would be okay to downscale these Machines

@elmiko elmiko force-pushed the provider-options-refactor branch 3 times, most recently from f60b7f0 to 1afa484 Compare September 30, 2025 02:49
@elmiko
Copy link
Contributor Author

elmiko commented Sep 30, 2025

/test pull-cluster-autoscaler-e2e-azure-master

@elmiko
Copy link
Contributor Author

elmiko commented Sep 30, 2025

the circular import in the unit tests is giving me some problems, not quite sure where it's starting.

@elmiko
Copy link
Contributor Author

elmiko commented Sep 30, 2025

i am not able to reproduce the unit test failure with the circular import locally. not sure the best course of action.

/retest

@elmiko
Copy link
Contributor Author

elmiko commented Sep 30, 2025

/retest-required

@elmiko
Copy link
Contributor Author

elmiko commented Sep 30, 2025

/retest

@elmiko
Copy link
Contributor Author

elmiko commented Sep 30, 2025

not sure why the tests aren't triggering.

This change helps to prevent circular dependencies between the core and
builder packages as we start to pass the AutoscalerOptions to the cloud
provider builder functions.
this changes the options input to the cloud provider builder function so
that the full autoscaler options are passed. This is being proposed so
that cloud providers will have new options for injecting behavior into
the core parts of the autoscaler.
this change adds a method to the AutoscalerOptions struct to allow
registering a scale down node processor.
This change adds a custom scale down node processor for cluster api to
reject nodes that are undergoing upgrade.
@elmiko elmiko force-pushed the provider-options-refactor branch from 1afa484 to a5f07fe Compare September 30, 2025 19:52
@elmiko
Copy link
Contributor Author

elmiko commented Sep 30, 2025

rebased on master

@elmiko
Copy link
Contributor Author

elmiko commented Sep 30, 2025

i'm not sure how i've broken this, but these error lines are not making sense to me:

package k8s.io/autoscaler/cluster-autoscaler/processors/customresources
	imports k8s.io/autoscaler/cluster-autoscaler/cloudprovider/gce from gpu_processor_test.go
	imports k8s.io/autoscaler/cluster-autoscaler/core/options from gce_cloud_provider.go
	imports k8s.io/autoscaler/cluster-autoscaler/processors from autoscaler.go
Error: 	imports k8s.io/autoscaler/cluster-autoscaler/processors/customresources from processors.go: import cycle not allowed in test

@elmiko
Copy link
Contributor Author

elmiko commented Sep 30, 2025

@towca does this error looks familiar to you at all?

this change removes the import from the gce module in favor of using the
string value directly.
@elmiko
Copy link
Contributor Author

elmiko commented Sep 30, 2025

ok, think my last commit on this chain fixed the circular import.

@jackfrancis
Copy link
Contributor

We have a conversation going on here that will potentially improve the gpu node label concern that this PR encountered:

/lgtm
/approve
/hold

for @towca to give his thumbs up

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 2, 2025
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 2, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: elmiko, jackfrancis

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 2, 2025
@elmiko
Copy link
Contributor Author

elmiko commented Oct 3, 2025

We have a conversation going on here that will potentially improve the gpu node label concern that this PR encountered:

i'm fine to change the label in the test for this PR, i was just trying to stop the circular import error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/cluster-autoscaler area/provider/alicloud Issues or PRs related to the AliCloud cloud provider implementation area/provider/aws Issues or PRs related to aws provider area/provider/azure Issues or PRs related to azure provider area/provider/cluster-api Issues or PRs related to Cluster API provider area/provider/coreweave area/provider/digitalocean Issues or PRs related to digitalocean provider area/provider/equinixmetal Issues or PRs related to the Equinix Metal cloud provider for Cluster Autoscaler area/provider/externalgrpc Issues or PRs related to the External gRPC provider area/provider/gce area/provider/hetzner Issues or PRs related to Hetzner provider area/provider/huaweicloud area/provider/ionoscloud area/provider/kwok Issues or PRs related to the kwok cloud provider for Cluster Autoscaler area/provider/linode Issues or PRs related to linode provider area/provider/magnum Issues or PRs related to the Magnum cloud provider for Cluster Autoscaler area/provider/oci Issues or PRs related to oci provider area/provider/rancher area/provider/utho Issues or PRs related to Utho provider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CA ClusterAPI provider can delete wrong node when scale-down occurs during MachineDeployment upgrade
5 participants